using System.IO;
using EntityKit.Editor;
using UnityEditor;
using UnityEngine;

namespace EntityKit.Editor
{
    public static class GenScripts
    {
        [MenuItem("Assets/Entity Kit/创建Event脚本", false, 0)]
        public static void CreateEventScript()
        {
            var loadSingletonScriptableObject = ScriptableObjectHelper.LoadSingletonScriptableObject<ScriptTemplateSettingConfig>();
            if (loadSingletonScriptableObject != null && loadSingletonScriptableObject.EventScriptTemplate != null)
            {
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile(AssetDatabase.GetAssetPath(loadSingletonScriptableObject.EventScriptTemplate), "NewEvent.cs");
            }
            else
            {
                Debug.LogError("找不到Event脚本模板配置或模板文件");
            }
        }
        
        [MenuItem("Assets/Entity Kit/创建状态机脚本", false, 10)]
        public static void CreateStateMachineScript()
        {
            var loadSingletonScriptableObject = ScriptableObjectHelper.LoadSingletonScriptableObject<ScriptTemplateSettingConfig>();
            if (loadSingletonScriptableObject != null && loadSingletonScriptableObject.StateMachineScriptTemplate != null)
            {
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile(AssetDatabase.GetAssetPath(loadSingletonScriptableObject.StateMachineScriptTemplate), "NewStateMachine.cs");
            }
            else
            {
                Debug.LogError("找不到状态机脚本模板配置或模板文件");
            }
        }
        
        [MenuItem("Assets/Entity Kit/创建MVCEntity脚本", false, 50)]
        public static void CreateMVCEntityScript()
        {
            var loadSingletonScriptableObject = ScriptableObjectHelper.LoadSingletonScriptableObject<ScriptTemplateSettingConfig>();
            if (loadSingletonScriptableObject != null && loadSingletonScriptableObject.EntityScriptTemplate != null)
            {
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile(AssetDatabase.GetAssetPath(loadSingletonScriptableObject.MVCEntityScriptTemplate), "NewMVCEntity.cs");
            }
            else
            {
                Debug.LogError("找不到MVCEntity脚本模板配置或模板文件");
            }
        }
        
        [MenuItem("Assets/Entity Kit/创建View脚本", false, 20)]
        public static void CreateViewScript()
        {
            var loadSingletonScriptableObject = ScriptableObjectHelper.LoadSingletonScriptableObject<ScriptTemplateSettingConfig>();
            if (loadSingletonScriptableObject != null && loadSingletonScriptableObject.ViewScriptTemplate != null)
            {
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile(AssetDatabase.GetAssetPath(loadSingletonScriptableObject.ViewScriptTemplate), "NewView.cs");
            }
            else
            {
                Debug.LogError("找不到View脚本模板配置或模板文件");
            }
        }
        
        [MenuItem("Assets/Entity Kit/创建Controller脚本", false, 30)]
        public static void CreateControllerScript()
        {
            var loadSingletonScriptableObject = ScriptableObjectHelper.LoadSingletonScriptableObject<ScriptTemplateSettingConfig>();
            if (loadSingletonScriptableObject != null && loadSingletonScriptableObject.ControllerScriptTemplate != null)
            {
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile(AssetDatabase.GetAssetPath(loadSingletonScriptableObject.ControllerScriptTemplate), "NewController.cs");
            }
            else
            {
                Debug.LogError("找不到Controller脚本模板配置或模板文件");
            }
        }
        
        [MenuItem("Assets/Entity Kit/创建Model脚本", false, 40)]
        public static void CreateModelScript()
        {
            var loadSingletonScriptableObject = ScriptableObjectHelper.LoadSingletonScriptableObject<ScriptTemplateSettingConfig>();
            if (loadSingletonScriptableObject != null && loadSingletonScriptableObject.ModelScriptTemplate != null)
            {
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile(AssetDatabase.GetAssetPath(loadSingletonScriptableObject.ModelScriptTemplate), "NewModel.cs");
            }
            else
            {
                Debug.LogError("找不到Model脚本模板配置或模板文件");
            }
        }
        
        [MenuItem("Assets/Entity Kit/创建Entity脚本", false, 50)]
        public static void CreateEntityScript()
        {
            var loadSingletonScriptableObject = ScriptableObjectHelper.LoadSingletonScriptableObject<ScriptTemplateSettingConfig>();
            if (loadSingletonScriptableObject != null && loadSingletonScriptableObject.EntityScriptTemplate != null)
            {
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile(AssetDatabase.GetAssetPath(loadSingletonScriptableObject.EntityScriptTemplate), "NewEntity.cs");
            }
            else
            {
                Debug.LogError("找不到Entity脚本模板配置或模板文件");
            }
        }
        
        [MenuItem("Assets/Entity Kit/创建EntityComponent脚本", false, 60)]
        public static void CreateEntityComponentScript()
        {
            var loadSingletonScriptableObject = ScriptableObjectHelper.LoadSingletonScriptableObject<ScriptTemplateSettingConfig>();
            if (loadSingletonScriptableObject != null && loadSingletonScriptableObject.EntityComponentScriptTemplate != null)
            {
                ProjectWindowUtil.CreateScriptAssetFromTemplateFile(AssetDatabase.GetAssetPath(loadSingletonScriptableObject.EntityComponentScriptTemplate), "NewEntityComponent.cs");
            }
            else
            {
                Debug.LogError("找不到EntityComponent脚本模板配置或模板文件");
            }
        }
    }
}